package com.hoopchina.data;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;

/**
 * List view base adapter class
 *   Adapters that subclasses this base class will be used in various kinds of list views
 *   including system default list view control and the custom unrolled list view
 * @author Si Wei
 * 
 */
public abstract class ListBaseAdapter extends BaseAdapter {
	protected LayoutInflater             mLayoutInflater;        // layout inflater
	protected int                        mResource;              // item layout resource
	protected List<?>                    mData;                  // list data
	protected Context                    mContext;               // parent
	protected OnClickListener            mClickListener;         // item click listener, not used in every case

	/**
	 * Constructor
	 * @param aContext parent
	 * @param aData list data
	 * @param aResource item layout resource
	 */
	public ListBaseAdapter(
			Context aContext,
			List<?> aData ) {
		mContext = aContext;
		mData = aData;
		mLayoutInflater = 
			( LayoutInflater )aContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
	}

	@Override
	public int getCount() {
		Log.i("ListBaseAdapter", "getCount="+mData.size());
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return mData.get( position );
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	public void removeItem(int position) {
		mData.remove(position);
	}
	@Override
	public abstract View getView(int position, View convertView, ViewGroup parent);
	
	/**
	 * Set item click listener
	 * @param aListener
	 */
	public void setItemOnClickListener( OnClickListener aListener ) {
		mClickListener = aListener;
	}

}
